package com.atguigu.zy.interview.jvm.reference;

import java.lang.ref.WeakReference;

/**
 * @author Jungle
 * @create 2022-09-04 14:56
 * 弱引用只要有gc就回收
 */
public class WeakReferenceDemo {
    public static void main(String[] args) {
        Object o1 = new Object();
        WeakReference<Object> weakReference = new WeakReference<>(o1);
        System.out.println(o1);
        System.out.println(weakReference.get());
        o1 = null;
        System.gc();
        System.out.println("========================");
        System.out.println(o1);
        System.out.println(weakReference.get());

    }
}
